﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddDishesCat.aspx.cs" Inherits="BuXiaChu.OrderDishes.Web.Admin.Restaurant.AddDishesCat" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register TagPrefix="Menu" TagName="Header" Src="~/Modules/Menu/Header.ascx" %>
<%@ Register TagPrefix="Menu" TagName="Footer" Src="~/Modules/Menu/Footer.ascx" %>
<%@ Register TagPrefix="Menu" TagName="CityLeft" Src="~/Modules/Menu/CityLeft.ascx" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link media="screen, projection" rel="stylesheet" type="text/css" href="/css/Blueprint/screen.css" />
    <link media="screen, projection" rel="stylesheet" type="text/css" href="/css/main.css" />

    <script type="text/javascript" src="../js/Extend.js"></script>

    <script type="text/javascript" src="../js/Common.js"></script>

    <script type="text/javascript" src="../js/jquery-vsdoc.js"></script>

</head>
<body>
    <div class="container">
        <Menu:Header ID="Header1" runat="server" />
        <form id="form1" runat="server">
        <Menu:CityLeft ID="menu_CityLeft" runat="server" />
        <div class="span-20 last">
            <div class="boxc">
            <a href="Index.aspx">返回餐厅管理</a><span>|</span>
                <a href="Dishes.aspx?restaurantId=<%= Request.QueryString["restaurantId"] %>&restaurantName=<%= Request.QueryString["restaurantName"] %>">菜品管理</a>                
                               <span>|</span>
                <a href="AddDishes.aspx?restaurantId=<%= Request.QueryString["restaurantId"] %>&restaurantName=<%= Request.QueryString["restaurantName"] %>">增加菜品</a>
            </div>
            <div class="boxc">
                <span>类别名称</span>
                <input type="text" id="txt_Name" />
                <input type="button" id="btn_Save" value="保存" />
                <span>餐馆名称：<%= HttpUtility.HtmlEncode(Request.QueryString["RestaurantName"]) %></span>
            </div>
            <div id="div_List" class="boxc">
                <table>
                    <tr>
                        <td>
                            类别编码
                        </td>
                        <td>
                            类别名称
                        </td>
                        <td>
                            操作
                        </td>
                    </tr>
                    <% foreach (var item in dishesCatList)
                       {%>
                    <tr>
                        <td>
                            <%=item.CatID %>
                        </td>
                        <td>
                            <span>
                                <%= HttpUtility.HtmlEncode(item.Name)%></span>
                            <input type="text" style="display: none;" id="txt_update_<%=item.CatID %>" size="30"
                                maxlength="100" value="<%= item.Name %>" />
                        </td>
                        <td>
                            <td data-id="<%=item.CatID %>">
                                <a href="javascript:;" onclick="shareCodeManager.modify(this)" id="aModify<%=item.CatID %>"
                                    opt="0">修改</a> <a href="javascript:;" onclick="shareCodeManager.del(this)" id="aDelete<%=item.CatID %>">
                                        删除</a> <a href="javascript:;" onclick="shareCodeManager.cancle(this)" id="aCancle<%=item.CatID %>"
                                            style="display: none">取消</a>
                            </td>
                        </td>
                    </tr>
                    <%} %>
                </table>
            </div>
        </div>
        </form>
        <Menu:Footer ID="Footer1" runat="server" />
    </div>
</body>
</html>

<script type="text/javascript">
    var shareCodeManager = {};
    shareCodeManager.opModify = "0";
    shareCodeManager.opSave = "1";
    shareCodeManager.url = "DishesCat.ashx";
    shareCodeManager.opSuccess = "操作成功";
    shareCodeManager.opFailed = "操作失败";
    shareCodeManager.getIdBy = function(o) {
        return o.parentNode.getAttribute("data-id");
    }
    shareCodeManager.getRestaurantId = function() {
        return <%=Request.QueryString["RestaurantId"] %>;
    }
    shareCodeManager.getUpdateTextBox = function(id) {
        return jDoc(String.format("#txt_update_{0}", id));
    }
    shareCodeManager.add = function(name, restaurantId) {
        $.post(this.url,
        { name: name, restaurantId: restaurantId, t: 2 }
        , function(data) {
            if (data.success) {
                jDoc.reload();
                alert(shareCodeManager.opSuccess);
            } else {
                alert(shareCodeManager.opFailed);
            }
        }, "json");
    }
    shareCodeManager.update = function(id,name) {
        $.post(this.url,
            {id:id, restaurantId: this.getRestaurantId(), name: name, t: 3 },
            function(data) {
                if (data.success) {
                    shareCodeManager.getUpdateTextBox(id).parentNode.getElementsByTagName("span")[0].innerHTML = name;
                    alert(shareCodeManager.opSuccess);
                } else {
                    alert(shareCodeManager.opFailed);
                }
            }, "json");
    }
    shareCodeManager.modify = function(o) {
        id = this.getIdBy(o);
        if (o.getAttribute("opt") == this.opModify) {
            this.classSetOpText(id, this.opSave);
        } else {
            var updateTextBox = this.getUpdateTextBox(id);
            var value = updateTextBox.value.trim();
            if (value != "") {
                oldValue = updateTextBox.parentNode.getElementsByTagName("span")[0].innerHTML.trim();
                if (value != oldValue) {
                    this.update(id, value);
                }
                this.classSetOpText(id, this.opModify);
            } else {
                alert(this.opClassNameEmpty);
                updateTextBox.focus();
            }
        }
    }
    shareCodeManager.del = function(o) {
        if (confirm("确认删除吗？")) {
                $.post(this.url,
                    { id: this.getIdBy(o), t: 4 },
                    function(data) {
                        if (data.success) {
                            jDoc.reload();
                            alert(shareCodeManager.opSuccess);
                        } else {
                            alert(shareCodeManager.opFailed);
                        }
                    }, "json");
            }
    }
    shareCodeManager.cancle = function(o) {
        this.classSetOpText(this.getIdBy(o), this.opModify);
    }

    shareCodeManager.classSetOpText = function(id, opt) {
        jDoc("aModify" + id).setAttribute("opt", opt);
        if (opt == this.opSave) {
            jDoc("aModify" + id).innerHTML = "保存";
            var tmp = this.getUpdateTextBox(id);
            tmp.parentNode.getElementsByTagName("span")[0].style.display = "none";
            tmp.style.display = "";
            tmp.focus();
            $("#aCancle" + id).show();
        } else {
            jDoc("aModify" + id).innerHTML = "修改";
            var updateTextBox = this.getUpdateTextBox(id);
            $(updateTextBox).hide();
            updateTextBox.parentNode.getElementsByTagName("span")[0].style.display = "";
            $("#aCancle" + id).hide();
        }
    }
</script>

<script type="text/javascript">
    jDoc.addEventHandler(jDoc("btn_Save"), "click", function() {
        var name = jDoc("txt_Name").value;
        if (name.trim() == "") {
            alert("请输入名称");
            jDoc("txt_Name").focus();
            return;
        }
        shareCodeManager.add(name, shareCodeManager.getRestaurantId());
    })
</script>

